<template>
  <!-- // 分配角色 -->
  <div>
    <el-checkbox-group v-model="roleIds" />
    <el-checkbox
      v-for="item in list"
      :key="item.id"
      :label="item.id"
    >{{ item.name }}
    </el-checkbox>
    <div style="margin-top: 20px; text-align: right">
      <el-button type="primary">确定</el-button>
      <el-button @click="closeDialog">取消</el-button>
    </div>
  </div>
</template>
<script>
import { getRoles } from '@/api/settings'
import { getUserDetailById } from '@/api/user'
export default {
  props: {
    curId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      roleIds: [],
      list: []
    }
  },
  created() {
    this.loadRoles()
  },
  methods: {
    closeDialog() {

    },
    async loadRoles() {
      try {
        const res = await getRoles({ page: 1, pagesize: 100 })
        console.log('getRoles', res)
        const detail = await getUserDetailById(this.curId)
        // 把当前这个用户拥有角色，让复选框处于选中状态
        this.roleIds = detail.data.roleIds
        this.list = res.data.rows
        console.log(this.curId, 'getUserDetailById')
        // 保存数据
      } catch (err) {
        console.log('getRoles', err)
      }
    }
  }
}
</script>
